/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
  let result = 0;
  for(let i = 0; i < prices.length - 1; i++) {
    if(prices[i + 1] >= prices[i])
      result += prices[i + 1] - prices[i];
  }
  return result;
};

const prices1 = [7, 1, 5, 3, 6, 4];
console.log(maxProfit(prices1));
const prices2 = [1, 2, 3, 4, 5];
console.log(maxProfit(prices2));
